package o;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import com.huawei.hms.framework.common.ContainerUtils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
import o.avx.a;

public class dxd implements ServiceConnection {
    private static final Object ˏ = new Object();
    private static List<LinkedHashMap<String, String>> ॱॱ = new ArrayList();
    private avx ʽ = null;
    private final AtomicInteger ˊ = new AtomicInteger();
    private String ˋ;
    private String ˎ;
    private String ॱ;

    public dxd(String str, String str2, String str3) {
        this.ˎ = str;
        this.ˋ = str2;
        this.ॱ = str3;
    }

    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        synchronized (ˏ) {
            this.ʽ = a.ˎ(iBinder);
        }
        try {
            Logger.ˎ("AppActiveServiceConnection", "set app active info to pps when service connect");
            this.ʽ.ॱ(this.ˎ, 0, this.ˋ, this.ॱ);
        } catch (RemoteException e) {
            Logger.e("AppActiveServiceConnection", "catch a RemoteException");
        } catch (Exception e2) {
            Logger.e("AppActiveServiceConnection", "catch a Exception");
        }
        for (int i = 0; i < ॱॱ.size(); i++) {
            for (Entry entry : ((LinkedHashMap) ॱॱ.get(i)).entrySet()) {
                String str = (String) entry.getKey();
                String[] split = ((String) entry.getValue()).split(ContainerUtils.FIELD_DELIMITER);
                String str2 = split[0];
                String str3 = split[1];
                try {
                    Logger.ˎ("AppActiveServiceConnection", "set app active cache info to pps");
                    this.ʽ.ॱ(str, 0, str2, str3);
                } catch (RemoteException e3) {
                    Logger.e("AppActiveServiceConnection", "catch a exception");
                }
            }
        }
        ॱॱ.clear();
        ˏ();
    }

    public void onServiceDisconnected(ComponentName componentName) {
        synchronized (ˏ) {
            this.ʽ = null;
        }
        this.ˎ = null;
        this.ˋ = null;
        this.ॱ = null;
    }

    public void ˊ(String str, String str2, String str3) {
        this.ˊ.incrementAndGet();
        synchronized (ˏ) {
            if (this.ʽ != null) {
                try {
                    Logger.ˎ("AppActiveServiceConnection", "set app active info to pps directly");
                    this.ʽ.ॱ(str, 0, str2, str3);
                } catch (RemoteException e) {
                    Logger.e("AppActiveServiceConnection", "catch a RemoteException");
                }
            } else {
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                linkedHashMap.put(str, str2 + ContainerUtils.FIELD_DELIMITER + str3);
                ॱॱ.add(linkedHashMap);
            }
        }
        this.ˊ.decrementAndGet();
        ˏ();
    }

    private void ˏ() {
        if (this.ˊ.get() <= 0) {
            ContentManager.getInstant().getContext().unbindService(this);
        }
    }
}
